{include file="public/header" /}
<style type="text/css">
	.aui-list-item-text .items-body img{}
</style>
<div class="container left-box mtb-15 ask-id-{$info['ask_id']}">
	<div class="col-md-9">
		<div class="question-detail">
			<div class="title">
				<h4>
					{gt name="info.reward" value="0"}
						<i class="icon-reward">{$info['reward']}</i>
					{/gt}
					{$info['title']}
				</h4>
			</div>
			<div class="content">{$info['content_img']}</div>
			<div class="info">
				<span class=""><a href="{:url('Question/index')}?category_id={$info['category_id']}">{$info['category_name']}</a></span>
				<span class="view_num"><i>{$info['update_view_num']}</i>浏览</span>
				<span class="user_name">
					{eq name="info.is_anonymous" value="1"}
						匿名
					{else/}
						<a href="{:url('People/index', array('user_id' => $info['user_id']))}">{$info['user_name']}</a>
					{/eq}
				</span>
				<span class="show_time">于 {$info['time_ago_desc']} 发布</span>
				<!-- <span>悬赏<i>{$info['reward']}</i>豆子</span> -->
				{eq name="_user_id" value="$info['user_id']"}
					{eq name="info.is_set_best" value="0"}
						<a class="eidt-ask" href="{:url('edit', array('ask_id' => $info['ask_id']))}"><i class="icon-edit"></i>修改</a>
					{/eq}
				{/eq}
			</div>
			{gt name="info.answer_id" value="0"}
				<div class="best-answer answer-id-{$best['answer_id']}">
					<div class="title">
						<span class="name"><i class="icon-best"></i>最佳答案</span>
						<span class="time">{$best['time_ago_desc']}</span>
					</div>
					<div class="content">
						{$best['content_img']}
					</div>
					<div class="opt">
						<a class="praise opt-tip {$best['is_praise'] ? 'on' : ''}" href="{:url('Answer/praise', array('answer_id' => $best['answer_id']))}">
							<i class="icon-praise"></i>
							<span class="praise_num">{$best['praise_num']}</span>
						</a>
						<a href="{:url('Comment/ajax_list', array('module' => 'ask_answer', 'object_id' => $best['answer_id']))}" class="btn btn-default view-comment" to="comment-{$best['answer_id']}">
							<i class="icon-comment"></i>评论
							<span class="comment_num">{$best['comment_num'] ? $best['comment_num'] : ''}</span>
						</a>
					</div>
					<div class="comment-box comment-{$best['answer_id']}">
						<div class="comment-list"></div>
						<div class="comment-submit row">
							<div class="col-md-12 reply-id">
								<div class="label label-info">
									回复：<span></span>
									<input type="hidden" name="reply_id" value="0">
									<i class="icon-error"></i>
								</div>
							</div>
							<div class="col-md-10">
								<input type="text" class="form-control comment-content" autocomplete="off" name="comment-content" placeholder="评论内容，请不要在评论里回答问题">
							</div>
							<div class="col-md-2">
								<button type="submit" style="width: 100%;" class="btn btn-info submit-comment" module="ask_answer" object-id="{$best['answer_id']}">提交评论</button>
							</div>
						</div>
					</div>
					<div class="user-info">
						{eq name="best.is_anonymous" value="0"}
							<a href="{:url('People/index', array('user_id' => $best['user_id']))}"><img src="{:img($best['user_head_url'], 100, 100)}" class="head"></a>
						{else/}
							<img src="{:img($best['user_head_url'], 100, 100)}" class="head">
						{/eq}
						<span class="name" style="margin-right: 15px;">
							{eq name="best.is_anonymous" value="0"}
								<a href="{:url('People/index', array('user_id' => $best['user_id']))}">{$best['user_name']}</a>
							{else/}
								匿名
							{/eq}
						</span>
						<span class="btn btn-default" disabled="disabled">问题：{$best['user_question_num']}</span>
						<span class="btn btn-default" disabled="disabled">回答：{$best['user_answer_num']}</span>
					</div>
				</div>
			{/gt}
			<div class="answer_num">{gt name="info.answer_id" value="0"}其它{/gt} {$list->total()} 个回答</div>
			{volist name="list" id="rs"}
				<div class="answer-list answer-id-{$rs['answer_id']}">
					<div class="user-head">
						{eq name="rs.is_anonymous" value="0"}
							<a href="{:url('People/index', array('user_id' => $rs['user_id']))}"><img src="{:img($rs['user_head_url'], 200, 200)}" alt=""></a>
						{else/}
							<img src="{:img($rs['user_head_url'], 200, 200)}" alt="">
						{/eq}
					</div>
					<div class="answer-info">
						<div class="user-info">
							<div class="name">
								{eq name="rs.is_anonymous" value="0"}
									<a href="{:url('People/index', array('user_id' => $rs['user_id']))}">{$rs['user_name']}</a>
								{else/}
									匿名
								{/eq}
							</div>
							<div class="time">{$rs['time_ago_desc']}</div>
						</div>
						<div class="content">
							{$rs['content_img']}
						</div>
						<div class="opt">
							{eq name="info.is_set_best" value="0"}
								{eq name="_user_id" value="$info['user_id']"}
									<a href="{:url('Answer/set_best', array('answer_id' => $rs['answer_id']))}" class="set_best btn-confirm-opt" msg="您确认设置此回答为最佳答案？"><i class="icon-best"></i>设为最佳</a>
								{/eq}
							{/eq}
							<a class="praise opt-tip {$rs['is_praise'] ? 'on' : ''}" href="{:url('Answer/praise', array('answer_id' => $rs['answer_id']))}">
								<i class="icon-praise"></i>
								<span class="praise_num">{$rs['praise_num']}</span>
							</a>

							<a href="{:url('Comment/ajax_list', array('module' => 'ask_answer', 'object_id' => $rs['answer_id']))}" class="btn view-comment" to="comment-{$rs['answer_id']}">
								<i class="icon-comment"></i>评论
								<span class="comment_num">{$rs['comment_num'] ? $rs['comment_num'] : ''}</span>
							</a>

							{eq name="_user_id" value="$rs['user_id']"}
								<a href="{:url('Answer/delete', array('answer_id' => $rs['answer_id']))}" class="btn btn-default btn-confirm-opt" msg="您确认要删除此回答？" del-class="answer-id-{$rs['answer_id']}"><i class="icon-error"></i>删除</a>
							{/eq}
						</div>
					</div>
				</div>
				<div class="comment-box comment-{$rs['answer_id']} answer-id-{$rs['answer_id']}">
					<div class="comment-list"></div>
					<div class="comment-submit row">
						<div class="col-md-12 reply-id">
							<div class="label label-info">
								回复：<span></span>
								<input type="hidden" name="reply_id" value="0">
								<i class="icon-error"></i>
							</div>
						</div>
						<div class="col-md-10">
							<input type="text" class="form-control comment-content" autocomplete="off" name="comment-content" placeholder="评论内容，请不要在评论里回答问题">
						</div>
						<div class="col-md-2">
							<button type="submit" style="width: 100%;" class="btn btn-info submit-comment" module="ask_answer" object-id="{$rs['answer_id']}">提交评论</button>
						</div>
					</div>
				</div>
			{/volist}
			{$page}
			<a name="answer-form"></a>
			<form class="answer-form" action="{:url('Answer/submit', array('ask_id' => $ask_id))}" is-cache-data="true">
				<div class="form-group">
					<textarea class="summernote_editor" id="summernote_editor" name="content" placeholder="您的回答是" style="width: 100%"></textarea>
				</div>
				<div class="form-group">
					<label class="pull-left anonymous"><input type="checkbox" name="is_anonymous" value="1">匿名</label>
					<label class="pull-left anonymous"><input type="checkbox" name="is_focus" value="1" checked>关注该问题</label>
					<button type="submit" class="btn btn-default pull-right">提交回答</button>
				</div>
			</form>
		</div>
	</div>
	<div class="col-md-3 right-box">
		<div class="question-btn" style="margin-bottom: 15px;">
			<button class="btn btn-block jump-answer">我要回答</button>
		</div>
		<div class="fav-attention">
			<a href="{:url('ask_fav', array('ask_id' => $info['ask_id']))}" class="btn btn-info opt-tip {$is_fav ? 'on' : ''}" on-text="已收藏" unon-text="收藏" class="btn btn-info">{$is_fav ? '已收藏' : '收藏'}</a>
			<span><i class="fav_num">{$info['fav_num']}</i> 收藏</span>
		</div>
		<div class="fav-attention">
			<a href="{:url('ask_focus', array('ask_id' => $info['ask_id']))}" class="btn btn-info opt-tip {$is_focus ? 'on' : ''}" on-text="已关注" unon-text="关注">{$is_focus ? '已关注' : '关注'}</a>
			<span><i class="focus_num">{$info['focus_num']}</i> 关注</span>
		</div>
	</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
	$('.jump-answer').click(function () {
		var top = parseFloat($('.answer-form').position().top);
		$(window).scrollTop(top);
	});
	$('.view-comment').click(function () {
		var _class      = $(this).attr('to');
		var url         = $(this).attr('href');
		var comment_num = parseFloat($(this).find('.comment_num').text());
		if(comment_num > 0 && $('.' + _class).css('display') == 'none' && $('.' + _class).find('.comment-list .item-box').size() == 0){
			$.ajax({
				url: url,
				type: "get",
				dataType : 'json',
				success: function(data) {
					removeLoading();
					var html = data.data.html;
					if(data.code == 1){
						$('.' + _class).find('.comment-list').html(html);
					}else{
						msgbox(data.msg, 'error');
					}
					$('.' + _class).slideToggle();
				},
				error:function(){
					removeLoading();
					msgbox('请求失败！', 'error');
				}
			});
		}else{
			$('.' + _class).slideToggle();
		}
		return false;
	});
	$('.submit-comment').click(function () {
		loading();
		var here      = $(this).parent().parent();
		var reply_id  = here.find('input[name="reply_id"]').val();
		var object_id = $(this).attr('object-id');
		var module    = $(this).attr('module');
			module    = module ? module : 'ask_answer';
		var content   = here.find('.comment-content').val();

		if(content.length == 0){
			msgbox('评论内容为空，不能提交！', 'error');
			$(this).parent().parent().find('.comment-content').focus();
			return false;
		}

		$.ajax({
			url: "{:url('Comment/submit')}?object_id=" + object_id,
			data: 'module=' + module + '&content=' + content + "&reply_id=" + reply_id,
			type: "post",
			dataType : 'json',
			success: function(data) {
				removeLoading();
				if(data.code == 1){
					msgbox(data.msg);

					here.find('.comment-content').val('');
					// 更新评论数量
					var comment_num = parseFloat($('.answer-id-' + object_id).find('.view-comment .comment_num').text());
					var comment_num = comment_num ? comment_num : 0;
					$('.answer-id-' + object_id).find('.view-comment .comment_num').text(comment_num + 1);

					// 显示评论内容
					var html = data.data.html;
					$('.comment-' + object_id).find('.comment-list').prepend(html);

					// 处理回复相关信息
					$('.comment-' + object_id + ' .reply-id input').val(0);
					$('.comment-' + object_id + ' .reply-id span').text('');
					$('.comment-' + object_id + ' .reply-id').hide();

					var scroll_top = $('.comment-' + object_id).position().top;
					$(window).scrollTop(scroll_top);
				}else{
					msgbox(data.msg, 'error');
				}
				//有返回链接，则跳转
				if(data.url){
					jumpurl(data.url);
				}
			},
			error:function(){
				removeLoading();
				msgbox('请求失败！', 'error');
			}
		});
	});
	$(document).on('click', '.reply-comment', function () {
		var object_id = $(this).attr('object-id');
		var reply_id  = $(this).attr('reply-id');
		var user_name = $(this).parent().parent().find('.user-name').text();
		$('.comment-' + object_id + ' .reply-id input').val(reply_id);
		$('.comment-' + object_id + ' .reply-id span').text(user_name);
		$('.comment-' + object_id + ' .reply-id').show();
		return false;
	});
	$('.reply-id .icon-error').click(function () {
		$(this).parent().find('input').val(0);
		$(this).parent().find('span').text('');
		$(this).parent().parent().hide();
	});
})
</script>

{include file="public/footer" /}